package com.copractice.data.dao.hibernate.question;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.copractice.data.dao.hibernate.HibernateDAO;
import com.copractice.data.dao.question.QuestionDAO;
import com.copractice.data.entity.question.Question;

/**
 * Implementation of <code>HibernateDAO</code> for <code>Question</code> class using <code>Hibernate</code> framework.
 * 
 * @author Dmitry Churbanov (dmitry.churbanov@gmail.com)
 * @version 1.0 03/14/2009
 */
public class HibernateQuestionDAO extends HibernateDAO<Question, Long> implements QuestionDAO {

    private static final Logger LOG = LoggerFactory.getLogger(HibernateQuestionDAO.class);    
    
    /**
     * @see com.copractice.data.dao.hibernate.HibernateDAO#getPersistenceClass
     */
    @Override
    protected Class<Question> getPersistenceClass() {
        if(LOG.isDebugEnabled()) {
            LOG.debug("Entity class was returned: {}", Question.class);
        }
        
        return Question.class;
    }
    
    @SuppressWarnings("unchecked")
    public List<Question> getQuestions(Long tagId) {
        if(LOG.isDebugEnabled()) {
            LOG.debug("Gets questions by tagId = '{}'", tagId);
        }
        
        return (List<Question>) getSession().getNamedQuery("QUESTIONS.findByTagId").setLong(0, tagId).list();
    }

}
